﻿#region Using Directives
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
#endregion

namespace DarkMatter.Tests
{
    public abstract class ChannelTestFixtureBase
    {
        protected Queue<byte[]> _channel1A_BytesRecievedQueue = new Queue<byte[]>();
        protected Queue<byte[]> _channel1B_BytesRecievedQueue = new Queue<byte[]>();

        protected void WireChannelsToRecieveQueues1aAnd1b(IChannel channel1A, IChannel channel1B)
        {
            channel1A.BytesRecieved += channel1A_BytesRecieved;
            channel1B.BytesRecieved += channel1B_BytesRecieved;
        }

        protected byte[] EncodeText(string text)
        {
            return Encoding.Unicode.GetBytes(text);
        }

        protected string DecodeText(byte[] bytes)
        {
            return Encoding.Unicode.GetString(bytes);
        }

        private void channel1B_BytesRecieved(IChannel source, byte[] bytes)
        {
            //Debug.WriteLine("channel1B_BytesRecieved");
            _channel1B_BytesRecievedQueue.Enqueue(bytes);
        }

        private void channel1A_BytesRecieved(IChannel source, byte[] bytes)
        {
            //Debug.WriteLine("channel1A_BytesRecieved");
            _channel1A_BytesRecievedQueue.Enqueue(bytes);
        }

        protected void Init()
        {
            _channel1A_BytesRecievedQueue.Clear();
            _channel1B_BytesRecievedQueue.Clear();
        }
    }
}
